package com.xbongbong.saas.help;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.formdata.pojo.dto.SaasAnalysisDataDTO;
import com.xbongbong.saas.enums.UpdateDataTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.model.AssembleModel;
import com.xbongbong.saas.model.BomBillModel;
import com.xbongbong.saas.model.ContractModel;
import com.xbongbong.saas.model.CostAdjustModel;
import com.xbongbong.saas.model.InstockModel;
import com.xbongbong.saas.model.InventoryModel;
import com.xbongbong.saas.model.OpportunityModel;
import com.xbongbong.saas.model.OutstockModel;
import com.xbongbong.saas.model.ProductionOrderModel;
import com.xbongbong.saas.model.PurchaseModel;
import com.xbongbong.saas.model.QuotationModel;
import com.xbongbong.saas.model.RefundModel;
import com.xbongbong.saas.model.ReturnedPurchaseModel;
import com.xbongbong.saas.model.TransferModel;
import com.xbongbong.saas.model.WorkOrderModel;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class FormatProductHelp {

    @Resource
    private ContractModel contractModel;
    @Resource
    private OpportunityModel opportunityModel;
    @Resource
    private RefundModel refundModel;
    @Resource
    private PurchaseModel purchaseModel;
    @Resource
    private ReturnedPurchaseModel returnedPurchaseModel;
    @Resource
    private InstockModel instockModel;
    @Resource
    private OutstockModel outstockModel;
    @Resource
    private TransferModel transferModel;
    @Resource
    private InventoryModel inventoryModel;
    @Resource
    private AssembleModel assembleModel;
    @Resource
    private BomBillModel bomBillModel;
    @Resource
    private ProductionOrderModel productionOrderModel;
    @Resource
    private WorkOrderModel workOrderModel;
    @Resource
    private QuotationModel quotationModel;
    @Resource
    private CostAdjustModel costAdjustModel;

    public void formatProduct(SaasAnalysisDataDTO saasAnalysisDataDTO, JSONObject data, List<FieldAttrEntity> explainList, boolean formCopy) throws XbbException {
        Integer businessType = saasAnalysisDataDTO.getBusinessType();
        XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(businessType);
        Long dataId = saasAnalysisDataDTO.getDataId();
        String corpid = saasAnalysisDataDTO.getCorpid();
        UpdateDataTypeEnum updateDataTypeEnum;
        if (formCopy){
            updateDataTypeEnum = UpdateDataTypeEnum.COPY;
        }else {
            updateDataTypeEnum = UpdateDataTypeEnum.UPDATE;
        }
        switch (xbbRefTypeEnum){
            case CONTRACT:
                contractModel.formatProduct4Show2(dataId,corpid,data,updateDataTypeEnum);
                break;
            case SALES_OPPORTUNITY:
                opportunityModel.formatProduct4Show2(dataId,corpid,data,updateDataTypeEnum);
                break;
            case REFUND:
                refundModel.formatProduct4Show2(dataId,corpid,data, updateDataTypeEnum);
                break;
            case SUPPLIER:
                break;
            case PURCHASE:
                purchaseModel.formatProduct4Show2(dataId,corpid,data,updateDataTypeEnum);
                break;
            case RETURNED_PURCHASE:
                returnedPurchaseModel.formatProduct4Show2(dataId,corpid,data, saasAnalysisDataDTO.getForProcess(), saasAnalysisDataDTO.getOperate(), updateDataTypeEnum);
                break;
            case INSTOCK:
            case PURCHASE_INSTOCK:
            case PRODUCTION_INSTOCK:
            case OTHER_INSTOCK:
            case RETURNED_MATERIEL_INSTOCK:
            case REFUND_INSTOCK:
                instockModel.formatProduct4Show2(dataId,corpid,data, saasAnalysisDataDTO.getForProcess(), saasAnalysisDataDTO.getOperate(), updateDataTypeEnum);
                break;
            case OUTSTOCK:
            case CONTRACT_OUTSTOCK:
            case PRODUCTION_MATERIEL_OUTSTOCK:
            case WORK_ORDER_OUTSTOCK:
            case OTHER_OUTSTOCK:
            case RETURNED_PURCHASE_OUTSTOCK:
                outstockModel.formatProduct4Show2(dataId,corpid,data, saasAnalysisDataDTO.getForProcess(), saasAnalysisDataDTO.getOperate(), updateDataTypeEnum);
                break;
            case TRANSFER:
                transferModel.formatProduct4Show2(dataId,corpid,data, saasAnalysisDataDTO.getForProcess(), saasAnalysisDataDTO.getOperate(), updateDataTypeEnum);
                break;
            case INVENTORY:
                inventoryModel.formatProduct4Show2(dataId,corpid,data, updateDataTypeEnum);
                break;
            case ASSEMBLE:
                assembleModel.formatProduct4Show2(dataId,corpid,data, saasAnalysisDataDTO.getForProcess(), saasAnalysisDataDTO.getOperate(), updateDataTypeEnum);
                break;
            case BOM_BILL:
                bomBillModel.formatProduct4Show2(dataId,corpid,data, updateDataTypeEnum);
                break;
            case PRODUCTION_ORDER:
                productionOrderModel.formatProduct4Show2(dataId,corpid,data, updateDataTypeEnum);
                break;
            case WORK_ORDER:
                workOrderModel.formatProduct4Show2(dataId,corpid,data,updateDataTypeEnum);
                break;
            case QUOTATION:
                quotationModel.formatProduct4Show2(dataId, corpid, data, updateDataTypeEnum);
                break;
            case COST_ADJUST:
                costAdjustModel.formatProduct4Show2(dataId, corpid, data, updateDataTypeEnum);
                break;
            default:
                break;
        }
    }
}
